package com.bj58.migrate.update.impl;

import java.util.List;

import org.apache.log4j.Logger;

import com.bj58.migrate.ScfProxy;
import com.bj58.migrate.update.AbsDataHandler;
import com.bj58.sfft.imc.entity.Info;
import com.bj58.sfft.imc.entity.InfoPara;
import com.bj58.sfft.imc.entity.ParaClass;

public class FanBaoCmcsHandleImpl extends AbsDataHandler{

	private Logger logger = Logger.getLogger( FanBaoCmcsHandleImpl.class );

	@Override
	public void deal( Info info, String args[] ){

		if( args != null && args.length > 1 ){

			List< ParaClass > old = info.getPara();
			boolean include = false;
			
			if( old != null ){
				
				for( ParaClass oldPara : old ){
					if( oldPara.getKey().equals( "9398" ) ){ // 包含9398
						include = true;
						oldPara.setValue( new InfoPara( 9398, args[ 2 ] ) );
					}
				}

				if( !include ){

					InfoPara infopara = new InfoPara();
					infopara.setParameterID( 9398 );
					infopara.setParameterValue( args[ 2 ] );

					ParaClass newPara = new ParaClass();

					newPara.setKey( "9398" );
					newPara.setValue( infopara );

					info.getPara().add( newPara );
				}
				try{
					info.Commit();
					ScfProxy.imc_InfoProviderWithIndex().UpdateInfo( info );
					logger.info( "Success " + args[ 2 ] + "  ---infoid:" + info.getInfoID() + "  -----userid:" + info.getUserID() );
				}
				catch( Exception e ){
					logger.error( "UpdateCate update info Exception---in " + args[ 2 ] + " ----infoid:" + info.getInfoID(), e );
				}
			}
		}
	}
}
